Foreground-aware image inpainting

ABSTRACT

In some embodiments, an image manipulation application receives an incomplete image that includes a hole area lacking image content. The image manipulation application applies a contour detection operation to the incomplete image to detect an incomplete contour of a foreground object in the incomplete image. The hole area prevents the contour detection operation from detecting a completed contour of the foreground object. The image manipulation application further applies a contour completion model to the incomplete contour and the incomplete image to generate the completed contour for the foreground object. Based on the completed contour and the incomplete image, the image manipulation application generates image content for the hole area to generate a completed image.

TECHNICAL FIELD

This disclosure relates generally to computer-implemented methods andsystems for computer graphics processing. Specifically, the presentdisclosure involves image inpainting or hole filling by taking intoaccount foreground objects in the image.

BACKGROUND

Image inpainting is the process of reconstructing lost or deterioratedparts of an image, also called hole filling. For example, imageinpainting can be used to fill the holes generated by removingdistracting objects from an image. Existing image inpainting techniquesfill holes in an image by borrowing information from image regionssurrounding the hole area. These existing techniques do not consider theinformation about the actual extent of foreground and background regionswithin the holes. As a result, they often produce noticeable artifactsin the completed image, especially near the contour of the foregroundobjects, if the hole area overlaps with or touches the foregroundobjects.

SUMMARY

Certain embodiments involve foreground aware image inpainting. In oneexample, an image manipulation application receives an incomplete imagethat includes a hole area. The hole area does not have image content.The image manipulation application applies a contour detection operationto the incomplete image. The contour detection operation detects anincomplete contour of a foreground object in the incomplete image. Thehole area prevents the contour detection operation from detecting acompleted contour of the foreground object. The image manipulationapplication further applies a contour completion model to the incompletecontour and the incomplete image. The contour completion model istrained to generate the completed contour for the foreground object. Theimage manipulation application generates image content for the hole areabased on the completed contour and the incomplete image to generate acompleted image.

These illustrative embodiments are mentioned not to limit or define thedisclosure, but to provide examples to aid understanding thereof.Additional embodiments are discussed in the Detailed Description, andfurther description is provided there.

BRIEF DESCRIPTION OF THE DRAWINGS

Features, embodiments, and advantages of the present disclosure arebetter understood when the following Detailed Description is read withreference to the accompanying drawings.

FIG. 1 depicts an example of a computing environment for usingforeground aware image inpainting to fill a hole area of an image,according to certain embodiments of the present disclosure.

FIG. 2 depicts an example of a process for generating image content fora hole area of an incomplete image based on a contour of a foregroundobject in the incomplete image to generate a completed image, accordingto certain embodiments of the present disclosure.

FIG. 3 depicts an example of a block diagram of the various softwaremodules used for foreground aware image inpainting, according to certainembodiments of the present disclosure.

FIG. 4 depicts an example of images and contours involved in theforeground aware image inpainting for an incomplete image, according tocertain embodiments of the present disclosure.

FIG. 5 depicts an example of a process for generating and training acontour completion model used in the foreground aware image inpainting,according to certain embodiments of the present disclosure.

FIG. 6 depicts an example of a process for generating and training imagecompletion model used in the foreground aware image inpainting,according to certain embodiments of the present disclosure.

FIG. 7 depicts an example of a computing system that executes an imagemanipulation application for performing certain embodiments of thepresent disclosure.

DETAILED DESCRIPTION

The present disclosure involves foreground aware image inpainting. Asdiscussed above, existing image inpainting methods often generateunsatisfactory results especially in filling a hole area that overlapswith or touches a foreground objects. Certain embodiments describedherein address these limitations by taking into account the foregroundobjects of an image to fill a hole area of the image. For instance, animage manipulation application detects a foreground object in an imagethat contains a hole area and extracts the contour of the foregroundobject. If the hole area overlaps with the foreground object, a portionof the contour of the object might fall in the hole area which preventsthe image manipulation application from detecting a completed contour ofthe foreground object. The image manipulation application detects anincomplete contour and employs a contour completion model to generate acompleted contour for the foreground object. The image manipulationapplication further generates the image content to fill the hole area ofthe image under the guidance of the completed contour so that the imagecontent is generated to respect the contour of the foreground object inthe image.

The following non-limiting example is provided to introduce certainembodiments. In this example, an image manipulation application receivesan image containing a hole area that does not have image content. Suchan image is also referred to herein as an “incomplete image.” As usedherein, the term “image” refers to a photo, a picture, a digitalpainting, a computer-generated graphic, or any other artifact thatdepicts visual perception.

The image manipulation application may employ a contour detection moduleto detect a contour of a foreground object of the incomplete image. Forexample, the contour detection module may detect a foreground object inthe incomplete image by employing a salient region segmentation methodto generate a foreground map. The contour detection module may furtherremove the noise from the foreground map and apply an edge detector todetect the contour of the foreground object. In some scenarios, the holearea overlaps the foreground object and contains a portion of thecontour of the foreground image. As a result, the detected contour ofthe foreground object may miss the portion that is covered by the holearea. Without the missing portion of the contour, image inpainting wouldbe performed with little guidance on the structure of the content of theimage leading to visible artifacts in the completed image especiallyaround the contour area.

The image manipulation application may further employ a contourcompletion module to generate the missing portion of the contour toarrive at a completed contour of the foreground object. Having thecompleted contour available to an inpainting operation can guide theinpainting process to avoid generating image content that isinconsistent with the structure foreground object reflected in itscontour. To generate the completed contour, the contour completionmodule may apply a machine-learning model (e.g., a generativeadversarial network (GAN)) that is trained to predict image contoursfrom a combination of input images and partial contours for thoseincomplete images. The image manipulation application can send thecompleted contour to an image complete module to fill the hole area ofthe incomplete image under the guidance of the completed contour. Theimage completion module may accept the incomplete image and thecompleted contour of the foreground object and apply them to an imagecompletion model, such as a GAN model, to fill the hole area of theincomplete image. The resulting image of the hole filling process isalso referred to herein as a completed image.

As described herein, certain embodiments provide improvements in imageprocessing by detecting, completing and using the contour of aforeground object of an image in the image inpainting process. Theinpainting process utilizes the contour of the foreground object todistinguish the foreground portion from the background portion of thehole area so that these two portions are treated differently to avoidintroducing visible artifacts in the completed image, especially nearthe contour of the foreground object. The foreground aware imageinpainting thus improves the visual quality of the completed image byrespecting the contour of the foreground object during image inpaintingthereby reducing or even eliminating the artifacts in the completedimage.

Example Operating Environment for Foreground Aware Image Inpainting

Referring now to the drawings, FIG. 1 depicts an example of a computingenvironment 100 for using foreground aware image inpainting to fill ahole area of an incomplete image 108. The computing environment 100includes a computing system 102, which can include one or moreprocessing devices that execute an image manipulation application 104 toperform foreground aware image inpainting and a model training system106 for training the various machine learning models used in theforeground aware image inpainting. The computing environment 100 furtherincludes a datastore 110 for storing data used in the image inpainting,such as the training data 112 used by the model training system 106.

The image manipulation application 104 can receive an incomplete image108 that contains a hole area 122 lacking image content. The hole area122 might be generated by a user removing unwanted content, such as adistracting object, from the image. The hole area 122 might also begenerated by the image manipulation application 104 or other imageprocessing applications by processing images, such as building athree-dimensional environment map based on a two-dimensional (2D) image,or generating a pair of stereo images from a single 2D image. Theincomplete image 108 might be generated in various other ways.Accordingly, the image manipulation application 104 can receive theincomplete image 108 by a user uploading or specifying the incompleteimage 108 or by receiving it from another software module within oroutside the image manipulation application 104.

To fill the hole area 122 of the incomplete image 108, the imagemanipulation application 104 can employ a contour detection module 114,a contour completion module 116 and an image completion module 118. Thecontour detection module 114 can be configured for detecting foregroundobjects 120 in the incomplete image 108 and extracting the contour ofthe foreground objects 120. If a foreground object 120 overlaps with thehole area 122, the contour of the foreground object 120 might also becorrupted, i.e. a portion of the object contour is missing, resulting inan incomplete contour. The image manipulation application 104 can employthe contour completion module 116 trained to generate the missingportion of the contour.

In one example, the contour completion module 116 can apply a machinelearning model, such as a GAN, to the incomplete contour. The output ofthe machine learning model can contain a completed contour of theforeground object 120. Using the completed contour as a guidance, theimage complete module 118 can fill the hole area 122 of the incompleteimage 108, for example, using another machine learning model trained togenerate a completed image 124 based on the incomplete image 108.Detailed examples of the contour detection module 114, the contourcompletion module 116 and the image completion module 118 contained inthe image manipulation application 104 are described herein with respectto FIG. 3.

To obtain the various models used in the above described imageinpainting process, the computing system 102 can employ the modeltraining system 106 to build and train the models. For example, themodel training system 106 can be configured to train the machinelearning model used by the contour completion module 116 to generate thecompleted contour, referred to herein as the “contour completion model.”Training the contour completion model can include generating trainingdata 112 for the model. The training data 112 can include trainingsamples each including an input and an output. The input in a trainingsample can include an incomplete image and an incomplete contour. Theoutput can include the corresponding completed contour. The trainingprocess can further involve adjusting the parameters of the contourcompletion model so that a loss function calculated based on the outputsof the contour completion model and the completed contours contained inthe training samples is minimized.

Similarly, the model training system 106 can also be configured to trainthe machine learning model used for generating the completed image 124,referred to herein as the “image completion model.” The training mayalso involve generating training data 112 for the image completionmodel. The training data 112 can include training samples each includingan input and an output. The input in a training sample can include anincomplete image, a completed contour and other types of data, such as ahole mask indicating the location of the hole area 122. The output caninclude the corresponding completed image. The training can furtherinvolve adjusting the parameters of the image completion model so that aloss function calculated based on the outputs of the image completionmodel and the completed images contained in the training samples isminimized. Detailed examples of training the contour completion modeland the image completion model are described herein with respect toFIGS. 5-6. Additional details regarding the foreground aware imageinpainting are described herein with respect to FIGS. 2-7.

Examples of Computer-Implemented Operations for Foreground Aware ImageInpainting

FIG. 2 depicts an example of a process 200 for generating image contentfor a hole area of an incomplete image based on a contour of aforeground object in the incomplete image to generate a completed image,according to certain embodiments of the present disclosure. It should benoted that in the example of the process 200 shown in FIG. 2, variousmodels used for generating the image content have been already beentrained. The training process of these models are discussed below withrespect to FIGS. 5 and 6. FIG. 2 is described in conjunction with FIG. 3where an example of a block diagram of the software modules used forforeground aware image inpainting is depicted. One or more computingdevices (e.g., the computing system 102) implement operations depictedin FIG. 2 by executing suitable program code (e.g., the imagemanipulation application 104). For illustrative purposes, the process200 is described with reference to certain examples depicted in thefigures. Other implementations, however, are possible.

At block 202, the process 200 involves receiving an incomplete image 108for image inpainting. For instance, the image manipulation application104 can receive the incomplete image 108 by a user operating in a userinterface presented by the image manipulation application 104 to selector otherwise specify the incomplete image 108. The image manipulationapplication 104 might also receive the incomplete image 108 from anothermodule of the image manipulation application 104 or another applicationexecuting on the computing system 102 or anther computing system. Theincomplete image 108 might be stored locally on the computing system 102or sent to the image manipulation application 104 via a network.

At block 204, the process 200 involves applying, to the incomplete image108, a contour detection operation that detects an incomplete contour ofa foreground object in the incomplete image 108. One or more computingdevices execute program code from the image manipulation application 104to implement block 204. For instance, the image manipulation application104 can apply a contour detection module 114 to detect a foregroundobject in the incomplete image 108 and extract the contour of theforeground object. FIG. 3 illustrates an example block diagram of thecontour detection module 114.

In the example shown in FIG. 3, the contour detection module 114includes an object detection module 302, a noise removal module 306 andan edge detector 310. The object detection module 302 can be configuredto detect foreground objects in the incomplete image 108. In oneexample, the object detection module 302 employs a salient regionsegmentation model to detect the foreground objects. For example,DeepCut can be utilized to detect the foreground objects. DeepCut is adeep learning-based technology for salient region segmentation from asingle image. To build a DeepCut model, a new dataset of personal imageswith humans, group of humans, pets, or other types of salient foregroundobjects are collected. Based on the new dataset, a deep neural networkis trained. The deep neural network has an architecture called DeepY-Net that includes low-level and high-level streams with dense blocksof boundary refinement to build a unified segmentation model for humans,group of humans, pets, and a generic model for segmenting arbitrarysalient objects.

Other segmentation mechanisms can also be utilized to identify theforeground objects. For instance, semantic segmentation can be utilizedto segment objects, such as a human or a car, based on understanding thecontent of the image. The segmentation model can be trained usingcomplete images and applied to the incomplete image 108 forsegmentation. The segmentation model can also be trained usingincomplete images with hole areas generated randomly.

Because the input incomplete image 108 contains a hole area 122, theresulting segmentation map 304 might include noises and is thus referredto as noisy segmentation map 304. The noises might be generated, forexample, by the object detection module 302 treating some hole areas asforeground objects or by the object detection module 302mischaracterizing certain regions as the foreground objects. To removethe noises in the noisy segmentation map 304, the contour detectionmodule 114 can utilize a hole mask of the incomplete image 108 thatindicates the position of the hole area in the incomplete image 108. Thehole mask can have the same size as the incomplete image 108 and caninclude binary values with 1s indicating the hole area and 0s indicatingnon-hole area, or vice versa. The hole mask can also use other values toindicate the hole area, such as non-binary integer values or realvalues. In another example, the hole mask might include three differentvalues indicating the foreground, the background and the hole area. Insome scenarios, the hole mask can accompany the incomplete image 108when the incomplete image 108 is received. In other scenarios, thecontour detection module 114 can generate the hole mask based on theincomplete image 108.

The object detection module 302 can use the hole mask to remove theregions in the segmentation map that may be mistakenly identified asforeground objects. In a further example, the noise removal module 306can apply connected component analysis to remove some of the smallclusters in the noisy segmentation map 304 to obtain a cleansegmentation map 308. Based on the clean segmentation map 308, thecontour detection module 114 can utilize the edge detector 310, such asthe Sobel operator, to detect the contour of the foreground object. Dueto the existence of the hole area, the detected contour might be anincomplete contour 312.

Referring back to FIG. 2, at block 206, the process 200 involvesapplying, to the incomplete contour 312 and the incomplete image 108, acontour completion model to generate a completed contour for theforeground object. One or more computing devices execute program codefrom the image manipulation application 104 to implement block 206. Forexample, the image manipulation application 104 can employ the contourcompletion module 116 trained to predict the missing portion of theforeground object contour. FIG. 3 illustrates an example block diagramof the contour completion module 116. In the example shown in FIG. 3,the contour completion module 116 employs a contour completion modelimplemented as a GAN to generate the completed contour. Specifically,the contour completion model includes a coarse contour generative model314, a refined contour generative model 318 and a contour discriminator322.

For example, the coarse contour generative model 314 can employ aconvolutional neural network, such as an encoder decoder network withseveral convolutional and dilated convolutional layers, to generate acoarse contour 316. The coarse contour 316 can be a rough estimate ofthe missing contours of the foreground object. The predicted contoursaround the holes might be blurry and might not be used as an effectiveguidance for the image completion module 118.

To infer a more accurate contour, the contour completion module 116 canemploy a refined contour generative model 318 that is configured toaccept the coarse contour 316 as an input, and output a more precisecontour to be used as the completed contour 320. In one implementation,the refined contour model 318 has a similar structure as the coarsecontour generative model 314, i.e. a convolutional neural network, suchas an encoder decoder network. In a further implementation, the refinedcontour generative model 318 can also include a contextual attentionlayer in the encoder decoder network to explicitly utilize surroundingimage features as references while inferring the missing values of thecontour. The contextual attention layer is a neural network layer whichallows neural feature matching or patch matching by implementing densepatch similarity computation with convolutional operations.

The contour discriminator 322 can be configured to determine whether thegenerated contour by the refined contour generative model 318 is real ornot. The contour discriminator 322 can be utilized at the training stageof the contour completion model to facilitate adjusting the parametersof the coarse contour generative model 314 and the refined contourgenerative model 318 to achieve a more precise generation of thecompleted contour. In one example, the contour discriminator 322 is afully convolutional PatchGAN discriminator that outputs a score mapinstead of a single score so as to tell the realism of different localregions of the generated completed contour 320. Additional details onusing the contour discriminator 322 in the training stage of the contourcompletion model are described herein with respect to FIG. 5.

Referring back to FIG. 2, at block 208, the process 200 involvesgenerating image content for the hole area based on the completedcontour 320 and the incomplete image 108 to generate a completed image124. One or more computing devices execute program code from the imagemanipulation application 104 to implement block 206. For example, theimage manipulation application 104 can employ an image completion module118 that is trained to predict the image content for the hole area ofthe incomplete image 108. The image completion module 118 can accept theincomplete image 108, the completed contour 320 of the foreground objectand other information as inputs, and output the completed image 124. Thecompleted contour 320 of the foreground object can provide a guidance tothe image completion module 118 regarding the foreground and thebackground regions of the incomplete image 108 so that the imagecompletion module 118 can fill the hole area without interrupting thecontours of the foreground object.

FIG. 3 illustrates an example block diagram of the image completionmodule 118. In the example shown in FIG. 3, the image completion module118 employs an image completion model implemented as a GAN to generatethe completed image 124. Similar to the contour completion model, theimage completion model includes a coarse image generative model 324, arefined image generative model 328 and an image discriminator 330.

The coarse image generative model 324, the refined image generativemodel 328 and the image discriminator 330 are similar to the coarsecontour generative model 314, the refined contour generative model 318and the contour discriminator 322, respectively, except that the inputsto these models of the image completion model are images rather thanobject contours. Specifically, the coarse image generative model 324 canaccept the incomplete image 108 as an input and generate a coarse image326 under the guidance of the completed contour 320. In one example, thecompleted contour 320 is binarized with a threshold, such as 0.5, beforebeing used by the image completion model, such as the coarse imagegenerative model 324 and the refined image generative model 328. In someimplementations, the image completion module 118 can also input the holemask to the coarse image generative model 324. In one example, thecoarse image generative model 324 employs a convolutional neuralnetwork, such as an encoder decoder network.

To further improve the quality of the output image, the coarse image 326generated by the coarse image generative model 324 can be fed into therefined image generative model 328 which generates a completed image124. The refined image generative model 328 can include a convolutionalneural network, such as an encoder decoder network. The refined imagegenerative model 328 can further include a contextual attention layer inthe encoder decoder network similar to the refined contour model 318 asdiscussed above. The contextual attention layer in the refined imagegenerative model 328 can be configured to match features inside the holearea to outside the hole area and borrow the features from outside thehole area to fill the hole area.

In some scenarios, it is likely that the generated image by the refinedimage generative model 328 does not respect the contour of the objectbecause the number of layers of mapping in the image completion modelbecomes high and the knowledge provided by the completed contour isweakened due to error accumulation. Thus, in one example, the completedcontour 320, or the binarized version of the completed contour 320, canbe again input into the refined image generative model 328 to guide thegeneration of the completed image 124.

Similar to the contour discriminator 322, the image discriminator 330can be used at the training stage of the image completion model andconfigured to determine whether the completed image 124 generated by therefined image generative model 328 is real or not. As will be discussedin detail later, the image discriminator 330 can facilitate theadjustment of the parameters of the coarse image generative model 326and the refined image generative model 328 to achieve a more precisegeneration of the completed image 124. Similar to the contourdiscriminator 322, the image discriminator 330 can also be implementedusing PatchGAN, or other types of discriminator. Additional detailsabout using the image discriminator 330 at the training stage of theimage completion model are described herein with respect to FIG. 6.

With the generated completed image 124, the image manipulationapplication 104 can satisfy the request for image inpainting by sendingthe completed image 124 to the requesting application or causing it tobe presented to a user, such as through a display device of thecomputing system 102 or other devices accessible to the user.

FIG. 4 depicts an example of images and contours involved in theforeground aware image inpainting for an incomplete image, according tocertain embodiments of the present disclosure. In the example shown inFIG. 4, incomplete image 402 includes background content, such as thebuilding, the cloud and the sun in the sky, and foreground content, suchas the car object 406. There is a hole area 404 in the incomplete image402 and the hole area 404 overlaps with the foreground car object 406,and corrupts the contour of the car object.

FIG. 4 further shows a segmentation map 408, which can be a cleansegmentation map 308 discussed above with regard to FIG. 3, where theforeground car object 406 is segmented out of the rest of the incompleteimage 402. Based on the segmentation map 408, the contour detectionmodule 114 detects the contour 410 of the foreground car object 406.Because the hole area 404 overlaps with the contour of the foregroundcar object 406, the detected contour 410 is an incomplete contour wherethe portion of the contour 410 that overlaps with the hole area 404 ismissing.

The contour completion module 116 accepts the incomplete contour 410 asan input along with other inputs such as the incomplete image 402 andgenerates a completed contour 412 using the coarse contour generativemodel 314 and the refined contour generative model 318 contained in thecontour completion model. The completed contour 412 is utilized by thecoarse image generative model 324 and the refined image generative model328 to generate image content for the hole area 404 and thus a completedimage 414 where the content of the right front portion of the car isfilled in by the image completion model.

Examples of Computer-Implemented Operations for Training Models Used inForeground Aware Image Inpainting

FIG. 5 depicts an example of a process 500 for generating and trainingcontour completion model used in the foreground aware image inpaintingas described above, according to certain embodiments of the presentdisclosure. One or more computing devices (e.g., the computing system102) implement operations depicted in FIG. 5 by executing suitableprogram code (e.g., the model training system 106). For illustrativepurposes, the process 500 is described with reference to certainexamples depicted in the figures. Other implementations, however, arepossible.

At block 502, the process 500 involves generating training data for thecontour completion model. In one example, the model training system 106generates the training data by collecting natural images that containone or more foreground objects. The images can be collected from publicdatasets, such as the MSRA-10K dataset and Flickr natural image dataset,or proprietary image datasets. Each collected image can be annotatedwith an accurate segmentation mask, either manually or automaticallyusing object segmentation techniques. To achieve a high accuracy in theresults of the image inpainting, the collected images contain diversecontent including a large variety of objects, such as animals, plants,persons, faces, buildings, streets and so on. The relative size ofobjects in each image also has a large variance so that the contourcompletion model can be exposed to a large variety of object sizes atthe training stage. In one implementation, the training images contain15,762 images among which 12,609 are used for training and 3,153 areused for testing.

To obtain the contour of segmented objects, the model training system106 can apply an edge detector, such as the Sobel edge operator, on thesegmentation mask. In one example, the mask C_(f) is obtained byapplying the Sobel operator: C_(f)=|G_(x)|+|G_(y)|, where G_(x) andG_(y) are the vertical and horizontal derivative approximations of thesegmentation mask, respectively. The model training system 106 canfurther binarize the mask with a thresholding mechanism and obtain abinary contour C_(gt) as the ground-truth contour of the training image.

In addition to the images and contours of the images, the model trainingsystem 106 can also generate the hole areas for each training image.Considering that in real-world inpainting applications, the distractorsthat users want to remove from images are usually arbitrarily shaped,the hole areas on each image are thus generated with arbitrary shapes.For example, the hole areas can be manually and randomly generated witha brush, or automatically generated by the model training system 106 ina random or pseudo-random way. In one example, the generated hole areashave two types: arbitrarily shaped holes that can appear in any regionof the input image and arbitrarily shaped holes that are restricted sothat they have no overlaps with the foreground objects.

For the first type of hole areas, it is likely that a hole area overlapswith a foreground object. This scenario is designed to handle the caseswhen unwanted objects are inside the foreground objects or partiallyocclude the foreground objects. The second type of hole areas aregenerated to simulate the cases where the unwanted regions ordistracting objects are behind the foreground objects. To generate thesecond type of hole areas, the model training system 106 can generate,or cause to be generated, randomly and arbitrarily shaped holes. Themodel training system 106 then removes the parts of holes that haveoverlap with the foreground objects. It should be understood that whilethe above process for generating training data is described in thecontext of training the contour completion model, it can be utilized togenerate the training data for training the image completion modeldescribed with regard to FIG. 6.

At block 504, the process 500 involves generating a GAN model thatincludes a generative model and a discriminator. In some examples, suchas the example shown in FIG. 3, the generative model includes a coarsecontour generative model and a refined contour generative model, and thediscriminator includes a contour discriminator. For each of the modelsin the GAN, the model training system 106 can determine model parameterssuch as the number of layers in the network involved in the model, theweights between layers, and other parameters. In some implementations,the model training system 106 can pre-train the models of the GAN usinga different dataset so that the training process described below usingthe training data generated at block 502 can converge faster.

At block 506, the process 500 involves determining the current stage ofthe training and assigning weights to different terms in a loss functionbased on the training stage. For the contour completion model shown inFIG. 3, the loss function includes three terms, one for the coarsecontour generative model 314, one for the refined contour generativemodel 318, and one for the contour discriminator 322. In one example,the loss terms for the coarse contour generative model 314 and therefined contour generative model 318 measures the content loss of thegenerated contours compared with the ground truth contours, and thusthese loss terms are also referred to as “content loss.” The loss termfor the contour discriminator 322 on the other hand is referred to as“adversarial loss.”

In one example, the model training system 106 can adopt curriculumtraining where the weights assigned to the terms in the loss functionvary over time and are determined based on the stages of the trainingprocess. In this example, the training is divided into three stages. Atthe first stage of the training process, the contour completion modeloutputs a rough contour and the model training system 106 focuses ontraining the generative model, i.e. the coarse contour generative model314 and the refined contour generative model 318. The model trainingsystem 106 thus assigns non-zero weight to the content loss terms andzero or close to zero weight to the adversarial loss.

At the second stage of the training process, the training starts toconverge. At this stage, the model training system 106 fine-tunes themodels using the contour discriminator 322 and assigns a non-zero weightto the adversarial loss. In one example, the weight of the adversarialloss compared to the weight of the content loss terms is made relativelysmall, such as 0.01:1, to avoid training failure due to the instabilityof the GAN loss for contour prediction. At the third stage of thetraining, the model training system 106 continues to fine-tune theentire contour completion model by assigning more weight to theadversarial loss. For example, the model training system 106 can makethe weight of adversarial loss and the weight of the content loss termsto be comparable, e.g. 1:1.

The different stages of the training process can be determined bycomparing the loss function or the difference between the generatedcompleted contour and the ground truth contour, to one or more thresholdvalues. For example, the model training system 106 can employ twothreshold values with one being higher than the other. If the lossfunction or the difference is above the higher threshold, the generatedcontour is a coarse contour and the training is determined to be at thefirst stage. If the loss function or the difference is below the higherthreshold, but above the lower threshold, the generated contour is moreaccurate than the coarse contour generated earlier and the training canbe determined to be at the second stage. If the loss function or thedifference is below the lower threshold, the generated contour is closeto the ground truth contour, the model training system 106 can determinethat the training is at the third stage.

This above example of determining training stage is for illustrationpurposes, and should not be construed as limiting. Various other ways ofdetermining the training stage can also be utilized, alone or incombination with the above described method. For example, the trainingstage can be determined by examining the changes in the loss functionsin consecutive iterations. The training can be determined to be at thefirst stage until the loss function starts to decrease from iteration toiteration, i.e. entering the second stage. Similarly, the training canbe determined to be at the third stage if the decrease in loss functionsof adjacent iterations slows down.

At block 508, the model training system 106 applies the training datagenerated at block 502 to the contour completion model. That is, theinputs in training samples can be fed into the coarse contour generativemodel 314 to generate respective coarse contours 316, which are fed intoto the refined contour generative model 318 to obtain completed contours320. The completed contours 320 can be further fed into the contourdiscriminator 322 to determine whether they are real or not. For each ofthe models, the model training system 106 can determine a loss functionterm. Denote the coarse contour 316 generated by the coarse contourgenerative model 314 as C_(C) ^(cos) and the completed contour 320output by the refined contour generative model 318 as C_(C) ^(ref).Further from the above description, the ground truth contour is denotedas C_(gt). The loss functions for the coarse contour generative model314 and the refined contour generative model 318 can be defined as theL1 or L2 distance between the respective output contour C_(C) ^(cos) orC_(C) ^(ref) and the ground truth contour C_(gt) in raw pixel space.These definitions, however, are likely to cause data imbalance problembecause the data in the contours are sparse.

To address this potential issue, the inherent nature of a contour can beutilized in one example, i.e., each pixel in the contour can beinterpreted as the probability that the pixel is a boundary pixel in theoriginal image. Accordingly, the contour can be treated as samples of adistribution, and the distance between the coarse contour 316 (or thecompleted contour 320) and the ground-truth contour can be calculated bycalculating the binary cross-entropy between each location. The modeltraining system 106 can further adopt a focal loss to balance theimportance of each pixel. Considering that the goal of the contourcompletion model is to complete the missing contours, more focus can beapplied on the pixels in the hole areas by applying a larger weight.

The loss function for the coarse contour generative model 314 can thusbe defined as follows:

_(con) ^(C)(C _(C) ^(cos) ,C _(gt) =αH(C _(C) ^(cos) −C _(gt))²

_(e)(C _(C) ^(cos) ,C _(gt))+(1−H)(C _(C) ^(cos) −C _(gt))²

_(e)(C _(C) ^(cos) ,C _(gt)),  (1)

where α is a parameter to adjust the relative weights applied to thepixels inside and outside the hole area. In one example, a takes a valuehigher than 1, such as 5 so that more weights are applied to the pixelsinside the hole area.

_(e)(x, y) is the binary cross-entropy loss function, and x and y arepredicted probability and the ground-truth probability, respectively.

_(e) (x, y) can be formulated as:

$\begin{matrix}{{\mathcal{L}_{e}( {x,y} )} = \{ {\begin{matrix}{- {\log (x)}} & {{{if}\mspace{14mu} y} = 1} \\{- {\log ( {1 - x} )}} & {otherwise}\end{matrix}.} } & (2)\end{matrix}$

The loss function

_(con) ^(C)(C_(C) ^(ref),C_(gt)) for the refined contour generativemodel 318 can be defined similarly by replacing C_(C) ^(cos) with C_(C)^(ref) in Eqn. (1). Since both the loss function

_(con) ^(C)(C_(C) ^(cos), C_(gt)) and the loss function

_(con) ^(C)(C_(C) ^(ref), C_(gt)) measure the difference between thegenerated contour by the respective model and the ground truth contour,these two loss functions form the content loss function

_(con) ^(C) of the contour completion mode, i.e.

_(con) ^(C)=

_(com) ^(C)(C _(C) ^(cos) ,C _(gt))+

_(con) ^(C)(C _(C) ^(ref) ,C _(gt))  (3)

The focal loss used above is helpful in generating a clean contour.However, in some scenarios although the edges in the uncorrupted regionscan be reconstructed well, the contours in the corrupted regions arestill blurry. To encourage the generative models to produce sharp andclean contours, the model training system 106 can further adopt thecontour discriminator 322 to perform adversarial learning where a hingeloss function is employed to determine whether the input to the contourdiscriminator 322 is real or fake. The loss function for the contourdiscriminator 322, i.e. the adversarial loss, for training the contourdiscriminator and the generator are as follows, respectively:

_(adv) ^(C) =E[σ(1−D ^(C)(C _(gt)))]+E[σ(1+D ^(C)(C _(C) ^(ref)))],  (4)

_(adv) =−E[D ^(C)(C _(C) ^(ref))],  (5)

where the σ(x) is the ReLU function, defined as σ(x)==max(0, x).

Training the GAN of the contour completion model involves a min-max gamebetween the discriminator and the generator. For each iteration of thetraining, the discriminator is trained by fixing the generator, and thenthe generator is trained by fixing the discriminator. In one example,the model training system 106 applies Eqn. (4) as the loss function forthe contour discriminator 322 when the contour discriminator 322 istrained and applies Eqn. (5) as the loss function for the contourdiscriminator 322 when the generator, i.e. the coarse contour generativemodel 314 and the refined contour generative model 318, are trained. Themodel training system 106 combines the content loss function defined inEqn. (3) and the adversarial loss defined in Eqn. (4) or (5) as theoverall loss function for the contour completion model based on theweights determined at block 506 for the respective terms.

At block 510, the process 500 involves adjusting the parameters of thecontour completion model to solve an optimization problem, such asminimizing the overall loss function. For illustration purposes, solvingthe optimization problem can involve performing iterative adjustments ofthe weights of the generative and discriminative models. The weights ofthe models can be iteratively adjusted so that the value of the lossfunction in a current iteration is smaller than the value of the lossfunction in an earlier iteration. At block 512, the process 500 involvesdetermining whether the training is complete and should be terminated.The model training system 106 can make this determination based on oneor more conditions no longer being satisfied. For example, the trainingiteration can stop if the decrease in the values of the loss function intwo adjacent iterations is no more than a threshold value.

If the model training system 106 determines that the training shouldcontinue, the process 500 involves another iteration where the modeltraining system 106 determines, at the block 506, the current trainingstage and the corresponding weights for the different terms in the lossfunction. If the model training system 106 determines that the trainingis complete, the process 500 involves outputting the trained contourcompletion model to the image manipulation application 104 so that itcan be used for foreground aware image inpainting.

FIG. 6, depicts an example of a process 600 for generating and trainingthe image completion model used in the foreground aware imageinpainting, according to certain embodiments of the present disclosure.The process 600 is similar to process 500 used to train the contourcompletion model.

At block 602, the model training system 106 generates the training datafor the image completion model. In one example, the model trainingsystem 106 uses the image dataset and the training incomplete imagesgenerated in block 502 of FIG. 5. At block 604, the model trainingsystem 106 generates the GAN for the image completion model by utilizinga similar architecture as the GAN for the contour completion model, i.e.a generator including a coarse image generative model 324 and a refinedimage generative model 328, and a discriminator including the imagediscriminator 330 as described above with respect to FIG. 3. In oneexample, the model training system 106 can pre-train the GAN for theimage completion model using another dataset, such as a large-scaleimage dataset, without considering the foreground object contour.

At block 606, the model training system 106 determines the trainingstage and the weights for different loss function terms in a way similarto that described above with respect to block 506 of FIG. 5. In otherwords, the curriculum training is also employed in the training of theimage completion model. Specifically, the model training system 106determines the current training stage of the image completion model. Ifthe model training system 106 determines that the training is at thefirst stage, such as by determining that the difference between thegenerated completed image and the ground truth completed image is largerthan a threshold value, the weight assigned to the image discriminator330 can be close to zero compared with the weights assigned to the lossterms corresponding to the coarse image generative model 324 and therefined image generative model 328. If the model training system 106determines that the training is at the second stage, such as bydetermining that the difference between the generated completed imageand the ground truth completed image is below a threshold value, theweight assigned to the image discriminator 330 can be small relative tothe weight assigned to the loss terms corresponding to the coarse imagegenerative model 324 and the refined image generative model 328. If themodel training system 106 determines that the training is at the thirdstage, such as by determining that the difference between the generatedcompleted image and the ground truth completed image is below a smallerthreshold value, the weight assigned to the image discriminator 330 canbe close to the weights assigned to the loss terms corresponding to thecoarse image generative model 324 and the refined image generative model328, such as 1:1.

At block 608, the process 600 involves applying the training data to theimage completion model and determining the loss function. The lossfunction for image completion model can also include a content loss,denoted as

_(con) ^(I) and an adversarial loss denoted as

_(adv) ^(I). The adversarial loss has a similar form as the loss termsfor the contour completion model defined in Eqn. (4) and (5), exceptthat the loss terms are applied to the images instead of the contours.For the content loss

_(con) ^(I), L1 loss is used in one example to minimize the distancebetween the generated image and the ground-truth image. The imagecontent loss is defined as:

_(con) ^(I) =∥I _(C) ^(cos) −I _(gt)∥₁ +∥I _(C) ^(ref) −I _(gt)∥₁,  (5)

where I_(C) ^(cos), I_(C) ^(ref) and I_(gt) are the output of the coarseimage model 324, the output of the refined image model 328, and theground-truth image, respectively. The overall loss function of the imagecompletion model can be determined to be

^(I) =w _(con)

_(con) ^(I) +w _(adv)

_(adv) ^(I),  (5)

where the weights of the content loss and the adversarial loss, i.e.w_(con) and w_(adv) are determined as described above with regard toblock 606 of the process 600.

The model training system 106 adjusts the parameters of the imagecompletion model at block 610 and determines whether the training iscompleted at block 612 similar to that described above for block 510 andblock 512, respectively. Likewise, similar to block 514, the modeltraining system 106, at block 614, sends the trained image completionmodel to the image manipulation application 104 for it to be used in theforeground aware image inpainting.

It should be appreciated that although in the above description, thecontour completion model and the image completion model are trainedseparately, they can be jointly trained. For example, a joint lossfunction can be established by, for example, generating a weighted sumof the loss functions for the contour completion model and the imagecompletion model. In one implementation, the weights for the two lossfunctions are equal. In another implementation, the weight of one lossfunction is higher than the weight of the other loss function in orderto tune the training process to focus on one of the models. Forinstance, a higher weight can be assigned to the loss function of theimage completion model than that of the contour completion model so thatthe image completion model can be trained with higher accuracy.

It should be further appreciated that although the above descriptionfocuses on using the contour of the foreground to guide the inpaintingprocess, other mechanisms can also be utilized. For example, asegmentation map, instead of the contour, of the foreground object canbe utilized. Consequently, a segmentation map completion model can begenerated to generate a completed foreground segmentation map. Thesegmentation map completion model may have a similar structure as thecontour completion model shown in FIG. 3, i.e. a GAN model with a coarsesegmentation model, a refined segmentation model, and a segmentationdiscriminator. The input to the segmentation completion model caninclude the incomplete image 108 and an incomplete segmentation map. Theincomplete segmentation map can be the noisy segmentation map 304 or theclean segmentation map 308. The loss function for the contour completionmodel can also be similarly defined, such as by using the binarycross-entropy loss function defined in Eqn. (2). Likewise, thecurriculum training described above for the contour completion model canalso be employed in the training of the segmentation completion model.Joint training of the segmentation completion model and the imagecompletion model can also be utilized.

In another example, the completed segmentation map can be generated bytraining and applying a machine learning model directly on theincomplete image 108 without generating an incomplete segmentation map.For example, the model used in the object detection module can bemodified to output a completed segmentation map based on the inputincomplete image 108. In another example, the machine learning model caninclude a GAN model with a similar structure as described in the aboveexample. Because incomplete segmentation map is not generated in thisexample, the input to the GAN model can just include the incompleteimage 108. Various other ways of generating the completed segmentationmap can also be employed.

Computing System Example for Implementing Foreground Aware ImageInpainting

Any suitable computing system or group of computing systems can be usedfor performing the operations described herein. For example, FIG. 7depicts an example of a computing system 700 that can implement thecomputing environment of FIG. 1. In some embodiments, the computingsystem 700 includes a processing device 702 that executes the imagemanipulation application 104, a model training system 106, or acombination of both, a memory that stores various data computed or usedby the image manipulation application 104 or the model training system106, an input device 714 (e.g., a mouse, a stylus, a touchpad, atouchscreen, etc.), and a display device 712 that displays graphicalcontent generated by the image manipulation application 104. Forillustrative purposes, FIG. 7 depicts a single computing system on whichthe image manipulation application 104 or the model training system 106is executed, and the input device 714 and display device 712 arepresent. But these applications, datasets, and devices can be stored orincluded across different computing systems having devices similar tothe devices depicted in FIG. 7.

The depicted example of a computing system 700 includes a processingdevice 702 communicatively coupled to one or more memory devices 704.The processing device 702 executes computer-executable program codestored in a memory device 704, accesses information stored in the memorydevice 704, or both. Examples of the processing device 702 include amicroprocessor, an application-specific integrated circuit (“ASIC”), afield-programmable gate array (“FPGA”), or any other suitable processingdevice. The processing device 702 can include any number of processingdevices, including a single processing device.

The memory device 704 includes any suitable non-transitorycomputer-readable medium for storing data, program code, or both. Acomputer-readable medium can include any electronic, optical, magnetic,or other storage device capable of providing a processor withcomputer-readable instructions or other program code. Non-limitingexamples of a computer-readable medium include a magnetic disk, a memorychip, a ROM, a RAM, an ASIC, optical storage, magnetic tape or othermagnetic storage, or any other medium from which a processing device canread instructions. The instructions may include processor-specificinstructions generated by a compiler or an interpreter from code writtenin any suitable computer-programming language, including, for example,C, C++, C#, Visual Basic, Java, Python, Perl, JavaScript, andActionScript.

The computing system 700 may also include a number of external orinternal devices, such as an input device 714, a display device 712, orother input or output devices. For example, the computing system 700 isshown with one or more input/output (“I/O”) interfaces 708. An I/Ointerface 708 can receive input from input devices or provide output tooutput devices. One or more buses 706 are also included in the computingsystem 700. The buses 706 communicatively couples one or more componentsof a respective one of the computing system 700.

The computing system 700 executes program code that configures theprocessing device 702 to perform one or more of the operations describedherein. The program code includes, for example, the image manipulationapplication 104, the model training system 106 or other suitableapplications that perform one or more operations described herein. Theprogram code may be resident in the memory device 704 or any suitablecomputer-readable medium and may be executed by the processing device702 or any other suitable processor. In some embodiments, all modules inthe image manipulation application 104 (e.g., the contour detectionmodule 114, the contour completion module 116, the image completionmodule 118, etc.) are stored in the memory device 704, as depicted inFIG. 7. In additional or alternative embodiments, one or more of thesemodules from the image manipulation application 104 are stored indifferent memory devices of different computing systems.

In some embodiments, the computing system 700 also includes a networkinterface device 710. The network interface device 710 includes anydevice or group of devices suitable for establishing a wired or wirelessdata connection to one or more data networks. Non-limiting examples ofthe network interface device 710 include an Ethernet network adapter, amodem, and/or the like. The computing system 700 is able to communicatewith one or more other computing devices (e.g., a computing device thatreceives inputs for image manipulation application 104 or displaysoutputs of the image manipulation application 104) via a data networkusing the network interface device 810.

An input device 714 can include any device or group of devices suitablefor receiving visual, auditory, or other suitable input that controls oraffects the operations of the processing device 702. Non-limitingexamples of the input device 714 include a touchscreen, stylus, a mouse,a keyboard, a microphone, a separate mobile computing device, etc. Adisplay device 712 can include any device or group of devices suitablefor providing visual, auditory, or other suitable sensory output.Non-limiting examples of the display device 712 include a touchscreen, amonitor, a separate mobile computing device, etc.

Although FIG. 7 depicts the input device 714 and the display device 712as being local to the computing device that executes the imagemanipulation application 104, other implementations are possible. Forinstance, in some embodiments, one or more of the input device 714 andthe display device 712 can include a remote client-computing device thatcommunicates with the computing system 700 via the network interfacedevice 710 using one or more data networks described herein.

General Considerations

Numerous specific details are set forth herein to provide a thoroughunderstanding of the claimed subject matter. However, those skilled inthe art will understand that the claimed subject matter may be practicedwithout these specific details. In other instances, methods,apparatuses, or systems that would be known by one of ordinary skillhave not been described in detail so as not to obscure claimed subjectmatter.

Unless specifically stated otherwise, it is appreciated that throughoutthis specification discussions utilizing terms such as “processing,”“computing,” “calculating,” “determining,” and “identifying” or the likerefer to actions or processes of a computing device, such as one or morecomputers or a similar electronic computing device or devices, thatmanipulate or transform data represented as physical electronic ormagnetic quantities within memories, registers, or other informationstorage devices, transmission devices, or display devices of thecomputing platform.

The system or systems discussed herein are not limited to any particularhardware architecture or configuration. A computing device can includeany suitable arrangement of components that provide a result conditionedon one or more inputs. Suitable computing devices include multi-purposemicroprocessor-based computer systems accessing stored software thatprograms or configures the computing system from a general purposecomputing apparatus to a specialized computing apparatus implementingone or more embodiments of the present subject matter. Any suitableprogramming, scripting, or other type of language or combinations oflanguages may be used to implement the teachings contained herein insoftware to be used in programming or configuring a computing device.

Embodiments of the methods disclosed herein may be performed in theoperation of such computing devices. The order of the blocks presentedin the examples above can be varied—for example, blocks can bere-ordered, combined, and/or broken into sub-blocks. Certain blocks orprocesses can be performed in parallel.

The use of “adapted to” or “configured to” herein is meant as open andinclusive language that does not foreclose devices adapted to orconfigured to perform additional tasks or steps. Additionally, the useof “based on” is meant to be open and inclusive, in that a process,step, calculation, or other action “based on” one or more recitedconditions or values may, in practice, be based on additional conditionsor values beyond those recited. Headings, lists, and numbering includedherein are for ease of explanation only and are not meant to belimiting.

While the present subject matter has been described in detail withrespect to specific embodiments thereof, it will be appreciated thatthose skilled in the art, upon attaining an understanding of theforegoing, may readily produce alterations to, variations of, andequivalents to such embodiments. Accordingly, it should be understoodthat the present disclosure has been presented for purposes of examplerather than limitation, and does not preclude the inclusion of suchmodifications, variations, and/or additions to the present subjectmatter as would be readily apparent to one of ordinary skill in the art.

1. A non-transitory computer-readable medium having program code that isstored thereon, the program code executable by one or more processingdevices for performing operations comprising: applying, to an incompleteimage comprising a hole area lacking image content, a contour detectionoperation that detects an incomplete contour of a foreground object inthe incomplete image, wherein a placement of the hole area prevents thecontour detection operation from detecting a completed contour of theforeground object; applying, to the incomplete contour and theincomplete image, a contour completion model that is trained to generatethe completed contour for the foreground object; and generating imagecontent for the hole area based on the completed contour and theincomplete image to generate a completed image.
 2. The non-transitorycomputer-readable medium of claim 1, wherein the contour completionmodel comprises a generative adversarial network (GAN) that comprises acoarse contour generative model, a refined contour generative model anda discriminative model.
 3. The non-transitory computer-readable mediumof claim 2, the operations further comprising training the contourcompletion model that comprises applying a loss function that comprisesa first loss term associated with content loss of the coarse contourgenerative model and the refined contour generative model and a secondloss term associated with adversarial loss of the discriminative model,wherein one or more weights applied to the first loss term and thesecond loss term change over time.
 4. The non-transitorycomputer-readable medium of claim 3, wherein the weights comprise afirst weight applied to the first loss term of the loss function and asecond weight applied to the second loss term of the loss function, andwherein a first ratio between the first weight and the second weight ata first stage of the training is higher than a second ratio between thefirst weight and the second weight at a second stage of the training. 5.The non-transitory computer-readable medium of claim 1, whereingenerating the image content for the hole area comprises applying animage completion model to the incomplete image and the completedcontour, the image completion model comprising a generative adversarialnetwork that comprises a generative model and a discriminative model. 6.The non-transitory computer-readable medium of claim 5, the operationsfurther comprising training the image completion model that comprisesapplying a loss function that comprises a first loss term associatedwith content loss of the generative model and a second loss termassociated with adversarial loss of the discriminative model, wherein afirst ratio between a first weight applied to the first loss term and asecond weight applied to the second loss term at a first stage of thetraining is higher than a second ratio between the first weight and thesecond weight at a second stage of the training.
 7. The non-transitorycomputer-readable medium of claim 6, wherein the generative modelcomprises a coarse image generative model and a refined image generativemodel, and wherein the first loss term defines content loss of thecoarse image generative model and content loss of the refined imagegenerative model.
 8. The non-transitory computer-readable medium ofclaim 1, wherein the contour detection operation comprises: detectingthe foreground object to generate a foreground map, wherein detectingthe foreground object comprises applying a contour model to theincomplete image; and generating the incomplete contour of theforeground object, wherein generating the incomplete contour comprisesapplying an edge detector to the foreground map.
 9. Acomputer-implemented method in which one or more processing devicesperform operations comprising: a step for generating image content for ahole area contained in an incomplete image based on a contour of aforeground object in the incomplete image to generate a completed image;and providing the completed image for display.
 10. Thecomputer-implemented method of claim 9, the operations furthercomprising training a contour completion model that comprises agenerative adversarial network (GAN), the GAN comprising a coarsecontour generative model, a refined contour generative model and adiscriminative model, wherein the step for generating image content forthe hole area comprises generating the contour of the foreground objectbased on the trained contour completion model.
 11. Thecomputer-implemented method of claim 10, wherein training the GANcomprises applying a loss function that comprises a first loss termassociated with content loss of the coarse contour generative model andthe refined contour generative model and a second loss term associatedwith adversarial loss of the discriminative model, wherein one or moreweights applied to the first loss term and the second loss term changeover time.
 12. The computer-implemented method of claim 11, wherein theweights comprise a first weight applied to the first loss term of theloss function and a second weight applied to the second loss term of theloss function, and wherein a first ratio between the first weight andthe second weight at a first stage of the training is higher than asecond ratio between the first weight and the second weight at a secondstage of the training.
 13. The computer-implemented method of claim 9,the operations further comprising training an image completion modelthat comprises a generative model and a discriminative model, whereinthe step for generating image content for the hole area comprisesapplying the trained image completion model to the incomplete image togenerate the completed image.
 14. The computer-implemented method ofclaim 13, wherein the training comprises applying a loss function thatcomprises a first loss term associated with content loss of thegenerative model and a second loss term associated with adversarial lossof the discriminative model, wherein a first ratio between a firstweight applied to the first loss term and a second weight applied to thesecond loss term at a first stage of the training is higher than asecond ratio between the first weight and the second weight at a secondstage of the training.
 15. The computer-implemented method of claim 14,wherein the generative model comprises a coarse image generative modeland a refined image generative model, and wherein the first loss termdefines content loss of the coarse image generative model and contentloss of the refined image generative model.
 16. A system comprising: aprocessing device; and a non-transitory computer-readable mediumcommunicatively coupled to the processing device, wherein the processingdevice is configured to execute program code stored in thenon-transitory computer-readable medium and thereby perform operationscomprising: detecting a foreground object in an incomplete image thatcomprises a hole area lacking image content; detecting an incompletesegmentation map of the foreground object based on a location of thehole area, wherein the location of the hole area prevents a completedsegmentation map of the foreground object from being detected;generating a completed segmentation map for the foreground object basedon the incomplete segmentation map and the incomplete image; andgenerating a completed image comprising generating image content for thehole area based on the completed segmentation map and the incompleteimage.
 17. The system of claim 16, wherein generating the completedsegmentation map comprises applying a segmentation map completion modelto the incomplete segmentation map and the incomplete image, thesegmentation map completion model comprising a generative adversarialnetwork (GAN) that comprises a coarse segmentation map generative model,a refined segmentation map generative model and a discriminative model.18. The system of claim 17, wherein generating the image content for thehole area comprises applying an image completion model to the incompleteimage and the completed segmentation map, the image completion modelcomprising a generative adversarial network that comprises a generativemodel and a discriminative model.
 19. The system of claim 18, whereinthe image completion model and the segmentation map completion model arejointly training to minimize a joint loss function defined based on afirst loss function for the image completion model and a second lossfunction for the segmentation map completion model.
 20. The system ofclaim 18, wherein the operations further comprise training the imagecompletion model that comprises applying a loss function that comprisesa first loss term associated with content loss of the generative modeland a second loss term associated with adversarial loss of thediscriminative model, wherein a first ratio between a first weightapplied to the first loss term and a second weight applied to the secondloss term at a first stage of the training is higher than a second ratiobetween the first weight and the second weight at a second stage of thetraining.